import { UserProfilesAPI } from "@/request/api";

export default {
    namespaced: true,
    state: {
        userInfo: {
            nickName: "",
            coin: 0,
            headImg:"",
        },
        cartTotal:0
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo = payload.userInfo
            state.cartTotal = payload.cartTotal
        },
        initUserInfo(state){
            state.userInfo = {
                //头像
                headImg: require("../../assets/img/userImg.f8bbec5e.png"),
                // 昵称
                nickName: "--",
                // 积分
                coin:'--'
            }
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            let res = await UserProfilesAPI();
            // console.log('actions', res.data);
            commit("changeUserInfo", res.data)
        }
    }
}